﻿<UserControl x:Class="SellAvi.Views.ControlTaskList"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:command="http://www.galasoft.ch/mvvmlight"
             xmlns:ctrl="clr-namespace:SellAvi.Views"
             mc:Ignorable="d"
             DataContext="{Binding UploadProduct, Source={StaticResource Locator}}"
             >
    <Grid>
        <DataGrid ItemsSource="{Binding TaskList}" x:Name="TaskDataGrid"
                  RowStyleSelector="{Binding DGStyleSelector}"
                  CanUserAddRows="False"
                  CanUserReorderColumns="True"
                  CanUserResizeColumns="True"
                  CanUserResizeRows="False"
                  CanUserSortColumns="True"
                  IsReadOnly="True"
                  Background="Transparent"
                  SelectionUnit="FullRow"
                  BorderThickness="0"
                  VerticalGridLinesBrush="Transparent"
                  HorizontalGridLinesBrush="Lavender"
                  AutoGenerateColumns="False">
            <!-- * Убираем границу при наводе фокуса на строку * -->
            <DataGrid.CellStyle>
                <Style TargetType="DataGridCell">
                    <Setter Property="BorderThickness" Value="0"/>
                    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                </Style>
            </DataGrid.CellStyle>
            <!-- * Цвет ряда при наведении фокуса (Brushes.Cornsilk)* -->
            <DataGrid.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="WhiteSmoke"/>
                <!--FFFFF8DC-->
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="#FF000000"/>
            </DataGrid.Resources>
            <!-- * Сохраняем все выделеные элементы * -->
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <command:EventToCommand Command="{Binding SelectTasksCommand}" CommandParameter="{Binding SelectedItems, ElementName=TaskDataGrid}" />
                </i:EventTrigger>
                <i:EventTrigger EventName="MouseDown">
                    <!--<command:EventToCommand Command="{Binding EditProductCommand}" CommandParameter="{Binding ElementName=ProductsDataGrid, Path=SelectedItem}" />-->
                    <command:EventToCommand Command="{Binding ClickTaskCommand}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <!-- * Удаление по кнопке * -->
            <DataGrid.InputBindings>
                <KeyBinding Key="Delete" Command="{Binding UnMarkProductCommand}" CommandParameter="{Binding ElementName=TaskDataGrid, Path=SelectedItems}"/>
            </DataGrid.InputBindings>
            <!-- * Контекстное меню для правого Клика * -->
            <DataGrid.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Перезапустить задачу" Command="{Binding ReUploadSelectedProductCommand}">
                        <MenuItem.Icon>
                            <Image Source="/SellAvi;component/Resources/reload.png" />
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="Удалить все" Command="{Binding UnMarkAllProductCommand}">
                    </MenuItem>
                    <MenuItem Header="Удалить выделенное" Command="{Binding UnMarkProductCommand}">
                        <MenuItem.Icon>
                            <Image Source="/SellAvi;component/Resources/trash.png" />
                        </MenuItem.Icon>
                    </MenuItem>
                </ContextMenu>
            </DataGrid.ContextMenu>


            <!--Описание колонок-->
            <DataGrid.Columns>
                <DataGridTemplateColumn Width="20">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <!--<TextBox DataContext ="{Binding}" Text="{Binding ResultStatus.OperationSucceeded}"></TextBox>-->
                            <Image Height="12" DataContext="{Binding}">
                                <Image.Style>
                                    <Style TargetType="{x:Type Image}">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding StatusCode}" Value="0">
                                                <Setter Property="Source" Value="/SellAvi;component/Resources/check.png" />
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding StatusCode}" Value="61">
                                                <Setter Property="Source" Value="/SellAvi;component/Resources/tongue.png" />
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding StatusCode}" Value="62">
                                                <Setter Property="Source" Value="/SellAvi;component/Resources/buy.png" />
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding StatusCode}" Value="63">
                                                <Setter Property="Source" Value="/SellAvi;component/Resources/binary.png" />
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding StatusCode}" Value="51">
                                                <Setter Property="Source" Value="/SellAvi;component/Resources/comment.png" />
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding StatusCode}" Value="52">
                                                <Setter Property="Source" Value="/SellAvi;component/Resources/time.png" />
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding StatusCode}" Value="41">
                                                <Setter Property="Source" Value="/SellAvi;component/Resources/tv.png" />
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding StatusCode}" Value="411">
                                                <Setter Property="Source" Value="/SellAvi;component/Resources/buy.png" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Image.Style>
                            </Image>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTextColumn Width="auto" Header="Задача" Binding="{Binding TaskName}" FontSize="10">
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell">
                            <Setter Property="Foreground" Value="LightGray"/>
                            <Style.Triggers>
                                <!--<DataTrigger Binding="{Binding Path=DataContext.CurrentAvitoTask.StatusCode, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}" Value="0">-->
                                <!--<DataTrigger Binding="{Binding Path=TaskName, Source=DataContext.TaskList}" Value="0">-->
                                <!--<DataTrigger Binding="{Binding Path=ItemsSource, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}}" Value="0">-->
                                <DataTrigger Binding="{Binding CurrentAvitoTask.StatusCode}" Value="{x:Null}">
                                    <Setter Property="Foreground" Value="Black"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>

                <DataGridTextColumn Width="*" Header="Описание" Binding="{Binding TaskDescription}" />
                <DataGridTextColumn Width="auto" Header="Время" Binding="{Binding TaskStatus.OperationStartTime, StringFormat=HH:mm:ss}"/>
                <DataGridTextColumn Width="225" Header="Статус" Binding="{Binding TaskStatus.OperationMessage}"/>

            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</UserControl>
